# -*- coding: utf-8 -*-
# @Time : 2023/10/29 2:16
# @Author : zxp

import socket
import time
import os

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 8001))

file_path = input("请输入文件路径：")
file_size = os.stat(file_path).st_size

client.sendall(str(file_size).encode('utf-8'))

print('准备')
time.sleep(2)
print('开始上传')
file_object = open(file_path, 'rb')
send_size = 0

while True:
    data = file_object.read(1024)  # 读取文件内容，1024字节
    client.sendall(data)  # 发送
    send_size += len(data)
    if send_size == file_size:
        break
client.close()
